// app.js
let host="https://ymy138.cn/base/"
//let host="http://127.0.0.1:1001/base/"
App({
  onLaunch() {
    // 展示本地存储能力

    // 登录
    wx.login({
      success: res => {
        console.log
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        wx.request({
          url: host+"api.Login/getOpenid",
          data:{
            code:res.code
          },
          method:"GET",
          success(res){

            let data = res.data
            if(data.code==2){
              wx.setStorageSync('openid', data.data)
              console.log(11111111)
              wx.redirectTo({
                url: '/pages/login/login',
                complete:function(r){
                  console.log("tiaoz",r)
                }
              }

              )
            }else if(data.code==1){
              console.log("getOpenid",data.data)
              wx.setStorageSync('userinfo',data.data)
              wx.setStorageSync('token',data.data.token)
              wx.redirectTo({
                url: '/pages/index/index',
                complete:function(r){
                  console.log("tiaoz",r)
                }
              }

              )
            }else{
              wx.showToast({
                title: res.info,
              })
            }
          }
        })
      }
    });

    wx.request({
      url: host+'api.Login/getSysName',
      method:"GET",
      success:function (res) {
        console.log("getSysName",res.data.data)
        wx.setStorageSync('sysname',res.data.data)
      }
    })

  },
  globalData: {
    userInfo: null
  }
})
